package cn.weiyuanbiao.DbGeneralCore;

import java.io.File;
import java.util.List;
import java.util.Map;

import cn.weiyuanbiao.DbGeneralCore.Constants;
import cn.weiyuanbiao.DbGeneralCore.util.DbConnUtil;
import cn.weiyuanbiao.DbGeneralCore.util.FileUtil;
import cn.weiyuanbiao.DbGeneralCore.util.TempleteUtil;

public class GenBean {
    static Map<String, Object> paraMap = Constants.paraMap;
    static String parentPackage = Constants.parentPackage;
    static String out = Constants.out;

    public static void createJava(String htmlName, String tableName, String packageName) {
//        paraMap.put("tableName", tableName);
        paraMap.put("db", DbConnUtil.getTable(tableName));
        packageName = parentPackage + packageName;
        paraMap.put("packageName", packageName);
        String filePath = System.getProperty("user.dir") + out + htmlName + "/" + tableName + ".java";
        System.out.println(filePath);
        TempleteUtil.createFileByTemplete("/html/" + htmlName + ".html", paraMap, filePath);
    }

    public static void createAll(String tableName, String packageName) {
        createJava("bean", tableName, packageName);
    }

    public static void createAllTables(String packageName) {
        List<String> tableNames = DbConnUtil.getAllTableName();
        for (String string : tableNames) {
            createAll(string, packageName);
        }
    }

    public static void main(String[] args) {
        FileUtil.deleteDir(new File(System.getProperty("user.dir") + out));
//		createAll("ConfigCopperShop", "copperShop");
        createAllTables("com.happy");
        System.out.println("自动编写完成");
    }
}
